package com.my.emf.notification.observers;



import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.util.EContentAdapter;

import com.my.emf.notification.model.IPerson;
import com.my.emf.notification.model.IPersonList;
import com.my.emf.notification.model.ModelFactory;

public class TotalObserver {
  private IPersonList persons;

  public TotalObserver() {
    ModelFactory factory = ModelFactory.eINSTANCE;
    persons = (IPersonList) factory.createIPersonList();

    EContentAdapter adapter = new EContentAdapter() {
      public void notifyChanged(Notification notification) {
        super.notifyChanged(notification);
        System.out
            .println("Notfication received from the data model. Data model has changed!!!");
      }
    };
    persons.eAdapters().add(adapter);
  }

  public void doStuff() {
    ModelFactory factory = ModelFactory.eINSTANCE;
    IPerson person = (IPerson) factory.createIPerson();
    person.setFirstName("Lars");
    System.out.println("I'm adding a person.");
    persons.getPersons().add(person);
    System.out.println("I'm changing a entry");
    IPerson person2 = persons.getPersons().get(0);
    person2.setFirstName("Lars2");

  }
} 
